babl-palette: speed up closest-color search
When constructing a palette format, calculate the distance between
each pair of colors in the palette, and for each color, construct a
list of all other colors and their distances from it, sorted by
distance. When searching for the closest palette color to a given
input pixel, based on the assumption that nearby pixels have
similar color, use the color list of the previous pixel's best
match, and use the triangle inequality to stop the search early.
See the code comments for more details.